package com.ruoyi.ncpsy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ncpsy.domain.NcpsyAgrProductArchive;
import com.ruoyi.ncpsy.service.INcpsyAgrProductArchiveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 农产品档案Controller
 * 
 * @author ruoyi
 * @date 2025-08-10
 */
@RestController
@Slf4j
@RequestMapping("/ncpsy/archive")
public class NcpsyAgrProductArchiveController extends BaseController
{
    @Autowired
    private INcpsyAgrProductArchiveService ncpsyAgrProductArchiveService;

    /**
     * 查询农产品档案列表
     */

    @GetMapping("/list")
    public TableDataInfo list(NcpsyAgrProductArchive ncpsyAgrProductArchive)
    {
        log.info("查询农产品档案列表");
        startPage();
        List<NcpsyAgrProductArchive> list = ncpsyAgrProductArchiveService.selectNcpsyAgrProductArchiveList(ncpsyAgrProductArchive);
        return getDataTable(list);
    }

    @GetMapping("/count")
    public int list1()
    {

        return  ncpsyAgrProductArchiveService.selectNcpsyAgrProductArchiveCount();
    }

    @GetMapping("/comCount")
    public int list2()
    {
        return  ncpsyAgrProductArchiveService.selectNcpsyAgrProductArchiveComCount();
    }

    /**
     * 导出农产品档案列表
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:archive:export')")
    @Log(title = "农产品档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcpsyAgrProductArchive ncpsyAgrProductArchive)
    {
        List<NcpsyAgrProductArchive> list = ncpsyAgrProductArchiveService.selectNcpsyAgrProductArchiveList(ncpsyAgrProductArchive);
        ExcelUtil<NcpsyAgrProductArchive> util = new ExcelUtil<NcpsyAgrProductArchive>(NcpsyAgrProductArchive.class);
        util.exportExcel(response, list, "农产品档案数据");
    }

    /**
     * 获取农产品档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:archive:query')")
    @GetMapping(value = "/{primaryId}")
    public AjaxResult getInfo(@PathVariable("primaryId") Long primaryId)
    {
        return success(ncpsyAgrProductArchiveService.selectNcpsyAgrProductArchiveByPrimaryId(primaryId));
    }

    /**
     * 新增农产品档案
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:archive:add')")
    @Log(title = "农产品档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcpsyAgrProductArchive ncpsyAgrProductArchive)
    {
        return toAjax(ncpsyAgrProductArchiveService.insertNcpsyAgrProductArchive(ncpsyAgrProductArchive));
    }

    /**
     * 修改农产品档案
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:archive:edit')")
    @Log(title = "农产品档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcpsyAgrProductArchive ncpsyAgrProductArchive)
    {
        return toAjax(ncpsyAgrProductArchiveService.updateNcpsyAgrProductArchive(ncpsyAgrProductArchive));
    }

    /**
     * 删除农产品档案
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:archive:remove')")
    @Log(title = "农产品档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{primaryIds}")
    public AjaxResult remove(@PathVariable Long[] primaryIds)
    {
        return toAjax(ncpsyAgrProductArchiveService.deleteNcpsyAgrProductArchiveByPrimaryIds(primaryIds));
    }
}
